#include <math.h>
#include "triangle.h"
#include "material.h"
#include "scene.h"
namespace gemren
{

	triangle::triangle(const size_t v0_, const size_t v1_, const size_t v2_, material_ptr inmat, material_ptr outmat)
		:v0(v0_),v1(v1_),v2(v2_),insidemat(inmat), outsidemat(outmat), datatype(1) {}

	void triangle::set_normals(const size_t n0_, const size_t n1_, const size_t n2_)
	{
		datatype |= 4;
		n0 = n0_; n1 = n1_; n2 = n2_;
	}
	void triangle::set_texcoords(const size_t t0_, const size_t t1_, const size_t t2_)
	{
		datatype |= 2;
		t0 = t0_; t1 = t1_; t2 = t2_;
	}
	float triangle::area(const scene* s) const
	{
		const coord& V0 = s->get_vertex(v0);
		return 0.5f * embree::length( embree::cross(s->get_vertex(v1)-V0, s->get_vertex(v2)-V0));
	}
}